Implement voltage cutoffs#13
Closed
DavidMStraub wants to merge 1 commit into
Closed
Conversation
Contributor
There was a problem hiding this comment.
Pull request overview
This PR adds explicit voltage cut-off termination behavior to the PyBaMM-backed cell blocks so PathSim simulations stop when the terminal voltage hits PyBaMM’s lower/upper voltage limits (addressing Issue #11’s “simulation never stops on under/over-voltage” problem).
Changes:
- Add
termination_events()to_CellBaseand_CoSimCellBaseto stop the simulation on under-/over-voltage. - Store voltage cut-off values (
_v_lower,_v_upper) from the active PyBaMM parameter set for both non-CoSim and CoSim blocks. - Improve CoSim initial outputs so the t=0 placeholder voltage is physically meaningful, and add tests covering under-voltage stop behavior.
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 5 comments.
| File | Description |
|---|---|
src/pathsim_batt/cells/pybamm_cell.py |
Adds voltage cut-off values and termination events for both integrated and co-simulated PyBaMM cell blocks; adjusts CoSim initial output computation and termination wiring. |
tests/cells/test_pybamm_cell.py |
Adds termination event integration tests to ensure simulations stop early at voltage cut-offs (primarily under-voltage scenarios). |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Comment on lines
+221
to
+225
| over_voltage = ZeroCrossingDown( | ||
| func_evt=lambda t: v_upper - float(outputs[0]), | ||
| func_act=lambda t: sim.stop(), | ||
| ) | ||
| return [under_voltage, over_voltage] |
Comment on lines
+402
to
+406
| def _over_cb(V: float) -> None: | ||
| if V >= v_upper: | ||
| sim.stop() | ||
|
|
||
| self._term_callbacks.extend([_under_cb, _over_cb]) |
| if V >= v_upper: | ||
| sim.stop() | ||
|
|
||
| self._term_callbacks.extend([_under_cb, _over_cb]) |
Comment on lines
+362
to
+364
| if self._just_stepped: | ||
| self._just_stepped = False | ||
| V = float(self.outputs[0]) |
Comment on lines
+640
to
+652
| PathSim does not stop on its own, and the voltage diverges wildly. | ||
| """ | ||
| cell = CellElectrical(initial_soc=0.02) | ||
| sim = self._run_without_events(cell, current=10.0, T_input_port="T_cell", T_value=298.15) | ||
| V_final = float(cell.outputs[0]) | ||
| # Without events the simulation runs the full 600 s | ||
| self.assertAlmostEqual(sim.time, 600.0, delta=10.0) | ||
| # And the voltage should have diverged to a physically impossible value | ||
| self.assertLess( | ||
| V_final, | ||
| 0.0, | ||
| "expected voltage divergence without termination events, got " | ||
| f"V={V_final:.3f} V — the bug may have been fixed elsewhere", |
Collaborator
Author
|
Closing as it wasn't a good design I think. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #11.